export const arrayValidator = (rule, value, callback) => {
  if (!value || !value.length) {
    callback(new Error(rule.message))
    return
  }
  callback()
}

export const welcom_step0_rules = {
  title: [{required: true, message: '请输入活码名称', trigger: 'blur'}],
  groupId: [{required: true, message: '请选择分组', trigger: 'blur'}],
  type: [{required: true, message: '请选择类型', trigger: 'blur'}],
  users: {required: true, trigger: 'change', message: '请选择员工', validator: arrayValidator}
}

export const greet_rules = {
  title: {required: true, message: '请输入标题', trigger: 'blur'},
  users: {required: true, trigger: 'change', message: '请选择员工', validator: arrayValidator}
}

export const control_rules = {
  teamName: {required: true, message: "请输入项目名称", trigger: 'blur'},
  teamType: {required: true, type: 'number', message: "请选择项目类型", trigger: 'change'}
}

export const qywxHorization = [
  {title: '配置企业微信ID', item: [{name: '输入企业微信ID', id: 1}]},
  {title: '配置企业通讯录', item: [{name: '输入通讯录Secret', id: 2}, {name: '设置通讯录接收事件服务器', id: 3}]},
  {title: '配置客服联系', item: [{name: '配置客服联系Secret', id: 4}, {name: '设置客服联系接收事件服务器', id: 5}, {name: '设置客户联系使用范围', id: 6}]},
  {title: '配置自建应用', item: [{name: '创建自建应用', id: 7}, {name: '设置自建应用ID和Secret', id: 8}, {name: '配置可调用的应用', id: 9}]},
  {title: '配置聊天侧边栏', item: [{name: '配置网页授权JS-SDK', id: 10}]},
]
/**
 * 时间快速选择
 */
export const pickerOptions = {
  shortcuts: [{
    text: '最近一周',
    onClick(picker) {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
      picker.$emit('pick', [start, end]);
    }
  }, {
    text: '最近一个月',
    onClick(picker) {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
      picker.$emit('pick', [start, end]);
    }
  }, {
    text: '最近三个月',
    onClick(picker) {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
      picker.$emit('pick', [start, end]);
    }
  }]
}
